Skip to content

Add execution status and error reporting to aksarc_jumpstart scripts#447

Draft
Copilot wants to merge 5 commits into
mainfrom
copilot/update-execution-status-message
Draft

Add execution status and error reporting to aksarc_jumpstart scripts#447
Copilot wants to merge 5 commits into
mainfrom
copilot/update-execution-status-message

Conversation

Copy link
Copy Markdown

Copilot AI commented Jan 23, 2026

The aksarc_jumpstart scripts lacked structured execution status reporting, making it difficult to identify which deployment step failed and troubleshoot issues.

Changes

All four scripts (jumpstart.ps1, jumpstart.sh, deployaksarc.ps1, deployaksarc.sh) now:

  • Track execution state: completed steps, failed step, error context, timestamps
  • Output structured status on both success and failure
  • Maintain proper exit codes for programmatic consumption

PowerShell implementation:

$executionStatus = @{
  Status = "InProgress"
  StartTime = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
  CompletedSteps = @()
  FailedStep = $null
  ErrorMessage = ""
  ExitCode = 0
}

Bash implementation:

print_execution_status() {
    echo "===== EXECUTION STATUS ====="
    echo "Status: $EXECUTION_STATUS"
    echo "Exit Code: $EXIT_CODE"
    echo "Completed Steps: ${COMPLETED_STEPS[*]}"
    # ... failure details if applicable
}

handle_error() {
    EXECUTION_STATUS="Failure"
    FAILED_STEP="$1"
    ERROR_MESSAGE="$2"
    print_execution_status
    exit "$3"
}

Example Output

On failure:

===== EXECUTION STATUS =====
Status: Failure
Failed Step: CreateVirtualMachine
Error Message: Failed to create virtual machine 'jumpstartVM'. Azure CLI command failed with exit code 1
Exit Code: 1
Completed Steps: CreateResourceGroup, CreateVirtualNetwork
Start Time: 2026-01-23 01:05:00
End Time: 2026-01-23 01:10:00
============================

On success:

===== EXECUTION STATUS =====
Status: Success
Exit Code: 0
Completed Steps: CreateResourceGroup, CreateVirtualNetwork, CreateVirtualMachine, AssignManagedIdentity, AssignContributorRole, EnableNestedVirtualization, ExecuteScript_initializedisk.ps1, ExecuteScript_0.ps1, ExecuteScript_1.ps1, ExecuteScript_deployazcli.ps1, ExecuteScript_deploymoc.ps1
Start Time: 2026-01-23 01:05:00
End Time: 2026-01-23 01:25:00
============================

Implementation Details

  • Bash scripts: Centralized error handling via handle_error() function
  • PowerShell scripts: Hashtable-based state tracking with inline error handling
  • Error handling: Added missing checks for role assignment and VM update operations
  • Code quality: Reduced duplication by extracting $scriptBaseName variable in deployaksarc.ps1

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 23, 2026 01:09
…messages

Co-authored-by: madhanrm <20309044+madhanrm@users.noreply.github.com>
…uplication

Co-authored-by: madhanrm <20309044+madhanrm@users.noreply.github.com>
Copilot AI changed the title [WIP] Update aksarc_jumpstart to return execution status and error message Add execution status and error reporting to aksarc_jumpstart scripts Jan 23, 2026
Copilot AI requested a review from madhanrm January 23, 2026 01:13
@madhanrm madhanrm closed this May 9, 2026
madhanrm and others added 2 commits May 9, 2026 00:46
Replace ~150 lines of duplicated Write-Host status blocks in jumpstart.ps1 and deployaksarc.ps1 with two reusable helpers:

- Write-ExecutionStatus: prints the status block (omits failure-only fields on success), mirroring the bash print_execution_status function.

- Invoke-StepFailure: records FailedStep / ErrorMessage / ExitCode, prints the status block, and exits, mirroring the bash handle_error function.

Behavior is unchanged: same status fields, same exit codes, same step names. Only structure is different. The PowerShell scripts now match the cleaner pattern already used in jumpstart.sh / deployaksarc.sh.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ROOT CAUSE 1 (silent failure): commandToExecute = 'powershell.exe -File X.ps1' completes with exit 0 even if the script wrote to Write-Error or otherwise failed without throwing. CustomScriptExtension reports Succeeded, ARM deployment returns 0, and the previous LASTEXITCODE / $? -ne 0 checks never fire. The script appears to succeed while actual deployment work failed.

ROOT CAUSE 2 (dead error checks under set -e): jumpstart.sh and deployaksarc.sh use 'set -e' followed by 'az ...; if [[ $? -ne 0 ]]; then handle_error ...'. Under set -e, the script exits at the failed az call before the if check runs, so handle_error never executes and the EXECUTION STATUS block is never printed -- a loud ARM failure also dies silently.

FIXES:

1. Extract status helpers into shared status-reporting.ps1 / status-reporting.sh dot-sourced from both scripts (removes ~150 lines of duplication).

2. New helper 'Invoke-VmScriptDeployment' (PS) / 'invoke_vm_script_deployment' (bash) ALWAYS queries the extension instance view after the deployment and treats ProvisioningState != succeeded as a failure, even when az deployment group create returned 0. On any failure it surfaces ProvisioningState message + StdOut + StdErr from the extension substatuses (instead of just 'az command failed with exit code N').

3. Replace every 'cmd; if [[ $? -ne 0 ]]; then handle_error' with 'cmd || handle_error ... $?' so error handlers actually run under set -e.

VALIDATION:

Added three test harnesses that mock 'az' to exercise success, silent-failure, loud-failure, noisy-success, and instance-view-unfetchable scenarios -- plus an integration test that runs the helper under 'set -e' to verify the EXECUTION STATUS block is printed and the script exits non-zero on both ARM and silent-extension failures. Run with:

  pwsh -NoProfile -File aksarc_jumpstart/tests/Test-StatusReporting.ps1

  bash aksarc_jumpstart/tests/test-status-reporting.sh

  bash aksarc_jumpstart/tests/test-integration-set-e.sh

All 12 scenarios pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@madhanrm madhanrm reopened this May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants